#include "ImageTab.h"

ImageTab::ImageTab(QWidget *parent):QWidget(parent)
{
	Q_UNUSED(parent);

	buildGridFunction();
	buildGridImage();
	mainLayout = new QFormLayout;
	mainLayout->addWidget(functionsGrid);
	mainLayout->addWidget(imageGrid);
	setLayout(mainLayout);
}

void ImageTab::buildGridFunction()
{
	functionsGrid = new QGroupBox(tr("Functions"));
	QHBoxLayout *layout = new QHBoxLayout;

	cropButton = new QPushButton(QIcon("../img/crop_ic.png"), tr("Crop"));

	layout->addWidget(cropButton);
	layout->addStretch();

	functionsGrid->setLayout(layout);
}

void ImageTab::buildGridImage()
{
	imageGrid = new QGroupBox(tr("Image"), this);
	QHBoxLayout *layout = new QHBoxLayout;
	//QLabel  *label_img  = new QLabel(this);
	//QPixmap *pixmap_img = new QPixmap("../img/cropimage.jpg");
	//label_img->setPixmap(*pixmap_img);
	//QObject::connect(m_bouton, SIGNAL(clicked()), native, SLOT(changeColor()));
	native = new PaintWidget(this);
	connect(cropButton, SIGNAL(clicked()), native, SLOT(cropImage()));

	layout->addWidget(native);

	//layout->addWidget(label_img);
	imageGrid->setLayout(layout);
}

void ImageTab::repaint()
{
	functionsGrid -> setTitle(tr("Functions"));
	cropButton -> setText(tr("Crop"));
	imageGrid-> setTitle(tr("Image"));
}

void ImageTab::paintImage(ImageObj** img)
{
	imageObj = img;
	native->paintImage(img);
}

ImageTab::~ImageTab(){}

